
#include <iostream>
#include <time.h>

namespace Y190606_PrintN {
void main();
void PrintN(int N);
void PrintN2(int N);
double f1(int n, double a[], double x) {
	int i;
	double p = a[0];
	for (i = 1; i <= n; ++i)
	{
		p += (a[i] * pow(x, i));
	}
	return p;
}

double f2(int n, double a[], double x) {
	int i;
	double p = a[n];
	for (i = n; i >0; --i)
	{
		p = a[i - 1] + x * p;
	}
	return p;
}

#define MAXK 1e7
#define MAXN 10

void main()
{
	int i;
	double a[MAXN];
	clock_t start, stop;
	double duration;
	for (i = 0; i < MAXN; ++i)
		a[i] = (double)i;

	start = clock();
	for(i=0;i<MAXK;++i)
		f1(MAXN - 1, a, 1.1);
	stop = clock();
	duration = ((double)(stop - start)) / CLK_TCK / MAXK;
	std::cout << "ticks1 = " << (double)(stop - start) << std::endl;
	std::cout << "duration1 = " << duration << std::endl;

	start = clock();
	for (i = 0; i < MAXK; ++i)
		f2(MAXN - 1, a, 1.1);
	stop = clock();
	duration = ((double)(stop - start)) / CLK_TCK / MAXK;
	std::cout << "ticks2 = " << (double)(stop - start) << std::endl;
	std::cout << "duration2 = " << duration << std::endl;

}

void main2() {
	int N = 10000;
	auto start = clock();
	PrintN(N);
	auto stop = clock();
	std::cout << ((double)(stop - start) / CLK_TCK) << std::endl;
	std::cout << CLK_TCK << std::endl;
}

void PrintN(int N) {
	int i=0;
	for (i = 1; i <= N; ++i) {
		//std::cout << i << std::endl;
	}
}

void PrintN2(int N) {
	if (N) {
		PrintN2(N - 1);
		//std::cout << N << std::endl;
	}
}

}

int main_190606_printN()
{
	Y190606_PrintN::main();
	return 0;
}

